<?php

defined('ACC')||exit('Access Denied');

class AdminUserModel extends Model{
	
	/* 添加用户注册密码 */
	public function reg($data){
		$data['passWord']=$this->encPass($data['passWord']);
		return $this->db->autoExecute($data,'user');
	}
	/* 密码 md5 加密 */
	public function encPass($passWord){
		return md5($passWord);
	}

	/* 检验用户名 */
	public function checkUser($userName,$passWord=''){
		if($passWord==''){
			$sql="select count(*) from user where username='$userName'";
			return $this->db->getOne($sql);
		}else{
			$passWord=$this->encPass($passWord);
			$sql="select user_id,username,email from user where username='$userName' and password='$passWord'";
			return $this->db->getRow($sql);
		}	
	}
	
	/* 修改上次登录时间 */
	public function upLog($user_id){
		$data=array('lastlogin'=>time());
		$this->db->autoExecute($data,'user','update',"user_id=$user_id");
	}
	
	/* 获取用户信息 */
	public function getUser($username){
		$sql = 'select user_id, username, email, password from admin_user where username = ' . "'$username'";
		return $this->db->getRow($sql);
	}
	
	/* 修改用户信息 */
	public function update($data, $user_id){
		$where = "user_id = '$user_id'";
		return $this->db->autoExecute($data, 'admin_user', 'update', $where);
	}
	
	
}




?>